<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            height: 3000px;
        }

        .goTop {
            width: 30px;
            height: 30px;
            background-color: pink;
            position: fixed;
            right: 50px;
            bottom: 50px;

            display: none;
        }
    </style>
</head>

<body>
    <div class="goTop"></div>

    <script src="../jquery/jquery-3.6.0.js"></script>

    <script>
        $(window).scroll(function () {
            if ($(this).scrollTop() > 500) {
                $(".goTop").css({ display: "block" })
            } else {
                $(".goTop").css({ display: "none" })
            }
        })

        $(".goTop").click(function () {
            $("html").animate(
                { scrollTop: 0 },
                500,
                () => console.log("动画完成")
            )
        })

    </script>
</body>

</html>